<table>
	<tr style="vertical-align: top;">
<?php



require("dbconn.php");

if (isset($_GET["id"]))
{
	$sid = $_GET["id"];
	
	if (isset($_GET["class"]))
	{
		$class = $_GET["class"] . "%";
		$QUERY = "
			SELECT SK.klas, S.uur, S.dag, S.week
			FROM studieuur S, studieuurklas SK
			WHERE SK.studieuur = S.id
			AND S.id = '$sid'
			AND SK.klas LIKE '$class'
		";
	}
	else
	{
		$QUERY = "
			SELECT SK.klas, S.uur, S.dag, S.week
			FROM studieuur S, studieuurklas SK
			WHERE SK.studieuur = S.id
			AND S.id = '$sid'
		";
	}
	//echo $QUERY;
	$resultheader = mysql_query($QUERY) or die(mysql_error());
	$columns = mysql_numrows($resultheader);


	for($i = 0; $i <$columns; $i++)
	{
		$header = mysql_result($resultheader, $i, "klas");// . " - " . mysql_result($resultheader, $i, "dag") . mysql_result($resultheader, $i, "uur"); // de manier waarop je info uit de db haalt
		$sid = $_GET["id"];
		
		$QUERY = "
			SELECT plaatsnr, vak, docentid, lokaal
			FROM plaats
			WHERE plaatsnr IN
			(
				SELECT plaatsnr
				FROM studieuurplaats
				WHERE studieuur IN
				(
					SELECT studieuur
					FROM studieuurklas
					WHERE klas = '$header'
					AND studieuur = $sid
				)
			)
			AND plaatsnr IN
			(
				SELECT plaatsnr
				FROM leerlingtoegang
				WHERE klas = '$header'
			)
			ORDER BY lokaal ASC, vak ASC, docentid ASC
			";
			
			////echo "<a style=\"display: none;\">$QUERY\n</a>\n";
			
		$resultdata = mysql_query($QUERY) or die (mysql_error());
		$rows = mysql_numrows($resultdata);

?>		<td>
			<table rules="top" id="<?php $rnd = mt_rand(10, 99); print($rnd); ?>" cellspacing="0" align="left" valign="top" class="hourtable">
				<tr><th class="uur" colspan="4"><?php print($header); ?></th></tr>
<?php

		for($j=0; $j < $rows; $j++)
		{
			$plaatsnr = mysql_result($resultdata, $j, "plaatsnr");
			$datavak = mysql_result($resultdata, $j, "vak");
			$datadocentid = mysql_result($resultdata, $j, "docentid");
			$datalokaal = mysql_result($resultdata, $j, "lokaal");



?>				<tr id="<?php print($i . $j); ?>" height="25">
					<td>
						<?php print($datavak); ?>
					</td>
					<td>
						<?php print($datadocentid); ?>
					</td>
					<td>
						<?php print($datalokaal); ?>
					</td>
					<td style="color: red;" width="20">
						<a class="actionbutton" onclick="delplacefromhour('<?php print("$header"); ?>', '<?php print("$plaatsnr"); ?>')"><img src="pics/delweek.png" /></a>
					</td>
				</tr>
<?php



		}
		
		
		
?>				<tr height="25">
					<td colspan="3" style="border-top: 2px solid black; border-right: 2px solid black; width: 100px !important;">
						voeg uur toe...
					</td>
					<td style="border-top: 2px solid black; width: 20px !important;">
								<a onclick="document.getElementById('choser_<?php print($header); ?>').style.display = (document.getElementById('choser_<?php print($header); ?>').style.display == '') ? 'none' : ''; document.getElementById('choosebtn_<?php print($header); ?>').src = (document.getElementById('choser_<?php print($header); ?>').style.display == 'block') ? 'pics/exphider.png' : 'pics/expchoser.png'" class="actionbutton">
							<img src="pics/expchoser.png" id="choosebtn_<?php print($header); ?>" />
						</a>
					</td>
				</tr>
				<tr height="25" style="display: none;" id="choser_<?php print($header); ?>">
					<td colspan="5" style="padding: 0;">
						<table rules="top" cellspacing="0" style="width: 126px; margin: 0; padding: 0; border: 0px solid black; border-top: 2px solid black; text-align: center;" align="left" valign="top">
<?php
		$QUERY = "
			SELECT plaatsnr, vak, docentid, lokaal
			FROM plaats
			WHERE plaatsnr IN
			(
				SELECT plaatsnr
				FROM studieuurplaats
				WHERE studieuur IN
				(
					SELECT studieuur
					FROM studieuurklas
					WHERE klas = '$header'
					AND studieuur = $sid
				)
			)
			AND plaatsnr NOT IN
			(
				SELECT plaatsnr
				FROM leerlingtoegang
				WHERE klas = '$header'
			)
			ORDER BY lokaal ASC, vak ASC, docentid ASC
			";
			
			////echo "<a style=\"display: none;\">$QUERY\n</a>\n";
			
		$resultdata = mysql_query($QUERY) or die (mysql_error());
		$rows = mysql_numrows($resultdata);

		if ($rows == 0)
		{
		
?>							<tr id="<?php print($i . $j); ?>" height="25" class="choser_hour" onclick="addplace('<?php print("$header"); ?>', '<?php print("$plaatsnr"); ?>')">
								<td>
									geen uren beschikbaar!
								</td>
							</tr>
<?php		

		}
		
		for($j=0; $j < $rows; $j++)
		{
			$plaatsnr = mysql_result($resultdata, $j, "plaatsnr");
			$datavak = mysql_result($resultdata, $j, "vak");
			$datadocentid = mysql_result($resultdata, $j, "docentid");
			$datalokaal = mysql_result($resultdata, $j, "lokaal");



?>							<tr id="<?php print($i . $j); ?>" height="25" class="choser_hour">
								<td>
									<?php print($datavak); ?>
								</td>
								<td>
									<?php print($datadocentid); ?>
								</td>
								<td>
									<?php print($datalokaal); ?>
								</td>
								<td style="color: red;" width="20">
									<a class="actionbutton" onclick="addplacetohour('<?php print("$header"); ?>', '<?php print("$plaatsnr"); ?>')"><img src="pics/addweek.png" /></a>
								</td>
							</tr>
<?php
		}
?>						</table>
					</td>
				</tr>
			</table>
		</td>
<?php



	}
}



?>	</tr>
</table>